package com.qpx.jxcbiz.web;


import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePrecreateRequest;
import com.alipay.api.response.AlipayTradePrecreateResponse;
import com.qpx.jxc.common.vo.ResultEntity;
import com.qpx.jxcbiz.config.alibaba.PayConfig;
import com.qpx.jxcstarterpay.service.AlipayService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class AlibabaPayContoller {


    @Autowired
    PayConfig payConfig;

    @Autowired
    RedisTemplate<String,String> redisTemplate;

    @Autowired
    AlipayService alipayService;


    @RequestMapping("/alibaba/pay")
    public ResultEntity pay(String orderNo) throws AlipayApiException {


        if (StringUtils.isNotBlank(redisTemplate.opsForValue().get(orderNo))){
            return ResultEntity.ok("支付二维码返回成功",redisTemplate.opsForValue().get(orderNo));
        }
        String qrcode = alipayService.getQrCode(orderNo);
        redisTemplate.opsForValue().set(orderNo,qrcode);
        return ResultEntity.ok("支付二维码返回成功",redisTemplate.opsForValue().get(orderNo));

    }
}
